package config

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gctx"
	"github.com/gogf/gf/v2/util/gutil"
	"zuhao-seucre/internal/common/model"
	"zuhao-seucre/internal/service"
)

type sConfig struct {
	TokenConf  *model.TokenConfig
	ZuHaoCache *model.ZuHaoCache
}

func New() *sConfig {
	var (
		tokenConfig *model.TokenConfig
		zuHaoCache  *model.ZuHaoCache
	)
	ctx := gctx.New()
	err := g.Cfg().MustGet(ctx, "zuHao.tokenConf").Scan(&tokenConfig)
	err = g.Cfg().MustGet(ctx, "zuHao.cache").Scan(&zuHaoCache)

	if err != nil {
		panic(err)
	}
	if gutil.IsEmpty(tokenConfig) {
		panic("tokenConf not config")
	}
	if gutil.IsEmpty(zuHaoCache) {
		panic("zuHaoCache not config")
	}

	return &sConfig{
		TokenConf:  tokenConfig,
		ZuHaoCache: zuHaoCache,
	}
}

func init() {
	service.RegisterConfig(New())
}

func (s *sConfig) MustGetTokenConf() *model.TokenConfig {
	return s.TokenConf
}

func (s *sConfig) MustGetZuHaoCache() *model.ZuHaoCache {
	return s.ZuHaoCache
}
